<?php

namespace App\Http\Controllers\Api;

use App\Models\Score;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;

class ScoresController extends Controller
{
    public function store(Request $request)
    {
        $validator =  Validator::make($request->all(), [
            'meet_id' => 'required',
            'question_one' => 'required|numeric|min:0|max:20',
            'question_two' => 'required|numeric|min:0|max:20',
            'question_three' => 'required|numeric|min:0|max:20',
            'question_four' => 'required|numeric|min:0|max:20',
            'question_five' => 'required|numeric|min:0|max:20',
            'sum' => 'required|numeric|min:0|max:100',
            'openid' => 'required',
        ]);
        if ($validator->fails()) {
            return response()->json(['msg' => '参数错误'])->setStatusCode(400);
        }
        $score = new Score();
        $score->fill($request->all());//变量填充
        $score->save();//变量存储数据
        return response()->json(['status' => true, 'createId' => $score->id ])->setStatusCode(201);
    }
    public  function findLog()
    {
        return response()->json(Score::all());
    }
}
